import wx

class HasEvents(object):
    
    def __getattr__(self, name):
        """
        register_click_event_for_authenticate_button
        ['register', 'button', 'event', 'for', 'authenticate', 'button']
        """
        items = name.split("_")
        
        if items[0] == "register":
            
            attr = getattr(self, '_'.join(items[4:]))
            event = getattr(wx, 'EVT_' + items[1])
            return lambda handler: self.Bind(event, lambda self, event: handler(), id=attr.GetId())
         
class MirrorButton(wx.Button):
    
    start_text = "Start/Resume/Update"
    pause_text = "Pause"
    
    def __init__(self, parent):
        wx.Button.__init__(self, parent, -1, self.start_text, (100, 80), (200, 30))
        
    def paused(self):
        self.SetLabel(self.start_text)
        
    def started(self):
        self.SetLabel(self.pause_text)
        
    def active(self):
        return self.GetLabel() == self.pause_text

class MainFrame(wx.Frame):
    
    def __init__(self, view, parent=None, id=-1, title="flickrmirror", size=(500, 150)):
        wx.Frame.__init__(self, parent, id, title, size=size)
        self.view = view
        
        #self.setup_menu_bar()
        self.CreateStatusBar()
        
        self.authenticate_button = \
            wx.Button(self, -1, "Authenticate", (20, 20), (120, 30))
        self.authenticate_text = \
            wx.StaticText(self, -1, '', (150, 23))
        self.Bind(
            wx.EVT_BUTTON, 
            self.view.authenticate_button_clicked, 
            id=self.authenticate_button.GetId()
        )
        
        self.backup_directory_button = \
            wx.Button(self, -1, "Mirror Location", (20, 50), (120, 30))
        self.backup_directory_text = \
            wx.StaticText(self, -1, '', (150, 53))
        self.Bind(
            wx.EVT_BUTTON,
            self.view.backup_directory_button_clicked,
            id=self.backup_directory_button.GetId()
        )
        
        self.mirror_button = MirrorButton(self)
        self.Bind(
            wx.EVT_BUTTON,
            self.view.mirror_button_clicked,
            id=self.mirror_button.GetId()
        )
        
        self.Centre()
        self.Show(True)
        
    def setup_menu_bar(self):
        menubar = wx.MenuBar()
        file = wx.Menu()
        file.Append(1, '&Quit', 'Exit flickrmirror')
        menubar.Append(file, '&File')
        self.SetMenuBar(menubar)
        
        #self.Bind(wx.EVT_MENU, self.OnClose, id=1)